//		ID : Xerxes
//      "I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define tp pair< int, pair<int,int> >
#define mmk( x, y , z ) mk( x, mk( y, z ) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}
int R,C;
char grid[101][101];
int cost[101][101];
int m[8][2]={ {-2,-1},{-2,+1},{+2,-1},{+2,+1},{+1,-2},{+1,+2},{-1,-2},{-1,+2} };
int v[8][2]={ {-1,-1},{-1,+1},{+1,-1},{+1,+1},{+0,-1},{+0,+1},{-1,+0},{+1,+0} };
inline void Read(){
	CI(R);
	CI(C);
	fo(i,0,R){
		fo(j,0,C){
			cin>>grid[i][j];
			cost[i][j] = (int)1023456789;
		}
	}
}
inline bool second_condition(int r, int c){
	if( grid[r][c]=='B' || grid[r][c]=='A' ){
		return false;
	}
	fo(i,0,8){
		int tr = m[i][0]+r;
		int tc = m[i][1]+c;
		if( tr < 0 || tc < 0 || tr >=R || tc >=C )continue;
		if( grid[tr][tc]=='Z' ){
			return true;
		}
	}
return false;
}
inline void bfs(int sx, int sy){
	queue< pair<int,int> > q;
	q.push( mk(sx,sy) );
	cost[sx][sy]=0;
	
	while( q.empty()==false ){
		pair<int,int> t = q.front();
		q.pop();
		
		fo(i,0,8){
			int tr = v[i][0]+t.f;
			int tc = v[i][1]+t.s;
			if( tr<0 || tc <0 || tr >= R || tc >=C )continue;
			if( grid[tr][tc]=='Z' )continue;
			if( second_condition(tr,tc) )continue;
			
			int ccost = cost[t.f][t.s]+1;
			if( ccost < cost[tr][tc] ){
				q.push( mk(tr,tc) );
				cost[tr][tc] = ccost;
			}
		}
	}
	
}

inline void Proc(){
	fo(i,0,R){
		fo(j,0,C){
			if( grid[i][j]=='A' ){
				bfs(i,j);
				goto L;
			}
		}
	}
L:
	fo(i,0,R){
		fo(j,0,C){
			if( grid[i][j]=='B' ){
				if( cost[i][j]<(int)1023456789 ){
					printf("Minimal possible length of a trip is %d\n",cost[i][j]);
				}
				else{
					printf("King Peter, you can't go now!\n");
				}
				return ;
			}
		}
	}
}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in","rt",stdin);
    #endif
    int cases=1;
    for( CI(cases) ; cases ; --cases ){
        Read();
        Proc();
    }

return 0;
}


